package com.ly.heart.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ly.common.core.domain.AjaxResult;
import com.ly.common.exception.CustomException;
import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.common.utils.erp.SnowflakeIdWorker;
import com.ly.heart.domain.dto.KingInventoryMaterialQueryDto;
import com.ly.heart.domain.dto.KingOrderMaterialQueryDto;
import com.ly.heart.domain.dto.KingProcureRefundMaterialQueryDto;
import com.ly.heart.domain.vo.OrderSumResult;
import com.ly.heart.mapper.KingInvoicePayableDetailMapper;
import com.ly.heart.service.IKingInvoicePayableDetailService;
import org.springframework.stereotype.Service;
import com.ly.heart.domain.KingInvoicePayableDetailEntity;

import javax.annotation.Resource;

/**
 * 金蝶-发票-应付单/采购开票明细Service业务层处理
 * @author wutao
 * @date 2024-06-26
 */
@Service
public class KingInvoicePayableDetailServiceImpl extends ServiceImpl<KingInvoicePayableDetailMapper, KingInvoicePayableDetailEntity> implements IKingInvoicePayableDetailService {

    @Resource
    private KingInvoicePayableDetailMapper kingInvoicePayableDetailMapper;

    /**
     * 查询金蝶-发票-应付单/采购开票明细
     * @param id 金蝶-发票-应付单/采购开票明细ID
     * @return 金蝶-发票-应付单/采购开票明细
     */
    @Override
    public KingInvoicePayableDetailEntity selectKingInvoicePayableDetailEntityById (String id) {
        return kingInvoicePayableDetailMapper.selectKingInvoicePayableDetailEntityById ( id );
    }

    /**
     * 查询金蝶-发票-应付单/采购开票明细列表
     * @param kingInvoicePayableDetailEntity 金蝶-发票-应付单/采购开票明细
     * @return 金蝶-发票-应付单/采购开票明细
     */
    @Override
    public List<KingInvoicePayableDetailEntity> selectKingInvoicePayableDetailEntityList (KingInvoicePayableDetailEntity kingInvoicePayableDetailEntity) {
        return kingInvoicePayableDetailMapper.selectKingInvoicePayableDetailEntityList ( kingInvoicePayableDetailEntity );
    }

    /**
     * 新增金蝶-发票-应付单/采购开票明细
     * @param kingInvoicePayableDetailEntity 金蝶-发票-应付单/采购开票明细
     * @return 结果
     */
    @Override
    public AjaxResult insertKingInvoicePayableDetailEntity (KingInvoicePayableDetailEntity kingInvoicePayableDetailEntity) {
        kingInvoicePayableDetailEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        kingInvoicePayableDetailEntity.setCreateBy ( SecurityUtils.getLoginUser ().getUser ().getUserId () );
        kingInvoicePayableDetailEntity.setCreateTime ( DateUtils.getNowDate () );
        boolean save = this.save ( kingInvoicePayableDetailEntity );
        if ( !save ) {
            throw new CustomException ( "新增采购开票（应付单）失败！" );
        }
        return AjaxResult.success ();
    }

    /**
     * 修改金蝶-发票-应付单/采购开票明细
     * @param kingInvoicePayableDetailEntity 金蝶-发票-应付单/采购开票明细
     * @return 结果
     */
    @Override
    public int updateKingInvoicePayableDetailEntity (KingInvoicePayableDetailEntity kingInvoicePayableDetailEntity) {
        kingInvoicePayableDetailEntity.setUpdateTime ( DateUtils.getNowDate () );
        return kingInvoicePayableDetailMapper.updateKingInvoicePayableDetailEntity ( kingInvoicePayableDetailEntity );
    }

    /**
     * 批量删除金蝶-发票-应付单/采购开票明细
     * @param ids 需要删除的金蝶-发票-应付单/采购开票明细ID
     * @return 结果
     */
    @Override
    public int deleteKingInvoicePayableDetailEntityByIds (String[] ids) {
        return kingInvoicePayableDetailMapper.deleteKingInvoicePayableDetailEntityByIds ( ids );
    }

    /**
     * 删除金蝶-发票-应付单/采购开票明细信息
     * @param id 金蝶-发票-应付单/采购开票明细ID
     * @return 结果
     */
    @Override
    public int deleteKingInvoicePayableDetailEntityById (String id) {
        return kingInvoicePayableDetailMapper.deleteKingInvoicePayableDetailEntityById ( id );
    }

    @Override
    public List<KingInvoicePayableDetailEntity> selectMaterialByOrderIdAndMaterialId(KingOrderMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.selectMaterialByOrderIdAndMaterialId(queryDto);
    }

    @Override
    public List<KingInvoicePayableDetailEntity> selectAdvanceMaterialByOrderIdAndMaterialId(KingOrderMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.selectAdvanceMaterialByOrderIdAndMaterialId(queryDto);
    }

    @Override
    public OrderSumResult getNumAndTotalTaxPriceByOrder(KingOrderMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getNumAndTotalTaxPriceByOrder(queryDto);
    }

    @Override
    public OrderSumResult getAdvanceNumAndTotalTaxPriceByOrder(KingOrderMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getAdvanceNumAndTotalTaxPriceByOrder(queryDto);
    }

    @Override
    public OrderSumResult getNumAndTotalTaxPriceByInventory(KingInventoryMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getNumAndTotalTaxPriceByInventory(queryDto);
    }

    @Override
    public List<KingInvoicePayableDetailEntity> getInvoicePayableDetailListByInventory(KingInventoryMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getInvoicePayableDetailListByInventory(queryDto);
    }

    @Override
    public OrderSumResult getNumAndTotalTaxPriceByProcureRefund(KingProcureRefundMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getNumAndTotalTaxPriceByProcureRefund(queryDto);
    }

    @Override
    public OrderSumResult getParentAmountMoneyAndTotalTaxPriceByProcureRefund(KingInventoryMaterialQueryDto queryDto) {
        return kingInvoicePayableDetailMapper.getParentAmountMoneyAndTotalTaxPriceByProcureRefund(queryDto);
    }

}
